﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminMasterPage.master" AutoEventWireup="true" CodeFile="Publishers.aspx.cs" Inherits="Admin_Publishers" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div id="featured-post">
        <h2>Quản lý thông tin nhà xuất bản</h2>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        AutoGenerateColumns="False" DataKeyNames="PublisherID" 
        DataSourceID="_sdsPublishers" onrowcommand="GridView1_RowCommand" 
        PageSize="3">
        <Columns>
            <asp:TemplateField InsertVisible="False" ShowHeader="False">
                <EditItemTemplate>
                    <asp:LinkButton ID="LinkButton6" runat="server" CommandName="Update">Update</asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton7" runat="server" CommandName="Cancel">Cancel</asp:LinkButton>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                        CommandName="Delete" Text="Delete"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="PublisherID" InsertVisible="False" 
                SortExpression="PublisherID">
                <EditItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("PublisherID") %>'></asp:Label>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("PublisherID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="PublisherName" SortExpression="PublisherName">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("PublisherName") %>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                        ControlToValidate="TextBox1" ErrorMessage="Trường bắt buộc"></asp:RequiredFieldValidator>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton5" runat="server" 
                        CommandArgument='<%# Bind("PublisherID") %>' CommandName="Edit" 
                        Text='<%# Bind("PublisherName") %>'></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Logo" SortExpression="Logo">
                <EditItemTemplate>
                    <table class="style6">
                        <tr>
                            <td class="style7">
                                <asp:Image ID="Image2" runat="server" Height="142px" 
                                    ImageUrl='<%# Bind("Logo") %>' Width="149px" />
                            </td>
                            <td class="style8">
                                <asp:Label ID="Label7" runat="server" Text="Chọn hình"></asp:Label>
                                <br />
                                <asp:FileUpload ID="FileUpload1" runat="server" />
                                <br />
                                <asp:Button ID="Button1" runat="server" CausesValidation="False" 
                                    CommandName="Upload" Text="Nạp lên" />
                            </td>
                        </tr>
                    </table>
                </EditItemTemplate>
                <HeaderTemplate>
                    <br />
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:Image ID="Image1" runat="server" Height="131px" 
                        ImageUrl='<%# Bind("Logo") %>' Width="144px" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Address" SortExpression="Address">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Address") %>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="TextBox3" runat="server" 
                        ErrorMessage="Trường bắt buộc"></asp:RequiredFieldValidator>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label4" runat="server" Text='<%# Bind("Address") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Phone" SortExpression="Phone">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Phone") %>'></asp:TextBox>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                        ControlToValidate="TextBox4" ErrorMessage="SĐT gồm 10 - 11 chữ số" 
                        ValidationExpression="\d{10,11}"></asp:RegularExpressionValidator>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label5" runat="server" Text='<%# Bind("Phone") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Description" SortExpression="Description">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label6" runat="server" Text='<%# Bind("Description") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <PagerTemplate>
            <asp:LinkButton ID="LinkButton1" runat="server" CommandName="New" 
                CausesValidation="False">New</asp:LinkButton>
            <br />
            <asp:LinkButton ID="LinkButton2" runat="server" CommandArgument="Prev" 
                CommandName="Page">Previous</asp:LinkButton>
            &nbsp;<asp:LinkButton ID="LinkButton3" runat="server" CommandArgument="Next" 
                CommandName="Page">Next</asp:LinkButton>
        </PagerTemplate>
        <EmptyDataTemplate>
            <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
                DataKeyNames="PublisherID" DataSourceID="_sdsPublishers" DefaultMode="Insert" 
                Height="50px" Width="560px" onitemcommand="DetailsView1_ItemCommand">
                <Fields>
                    <asp:BoundField DataField="PublisherID" HeaderText="PublisherID" 
                        InsertVisible="False" ReadOnly="True" SortExpression="PublisherID" />
                    <asp:TemplateField HeaderText="PublisherName" SortExpression="PublisherName">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("PublisherName") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("PublisherName") %>'></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                                ControlToValidate="TextBox1" ErrorMessage="Trường bắt buộc"></asp:RequiredFieldValidator>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("PublisherName") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Logo" SortExpression="Logo">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Logo") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <asp:Image ID="Image3" runat="server" Height="97px" 
                                ImageUrl='<%# Bind("Logo") %>' Width="116px" />
                            <br />
                            <asp:Label ID="Label8" runat="server" Text="Chọn hình"></asp:Label>
                            <br />
                            <asp:FileUpload ID="FileUpload2" runat="server" />
                            <br />
                            <asp:Button ID="Button2" runat="server" CommandName="Upload" 
                                 style="height: 26px" Text="Tải hình" CausesValidation="False" />
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("Logo") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Address" SortExpression="Address">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Address") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Address") %>'></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                                ControlToValidate="TextBox3" ErrorMessage="Trường bắt buộc"></asp:RequiredFieldValidator>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label3" runat="server" Text='<%# Bind("Address") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Phone" SortExpression="Phone">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Phone") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Phone") %>'></asp:TextBox>
                            <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" 
                                ControlToValidate="TextBox4" 
                                ErrorMessage="Số điện thoại bao gồm 10 - 11 chữ số"></asp:RegularExpressionValidator>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label4" runat="server" Text='<%# Bind("Phone") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="Description" HeaderText="Description" 
                        SortExpression="Description" />
                    <asp:TemplateField ShowHeader="False">
                        <InsertItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                                CommandName="Insert" Text="Insert"></asp:LinkButton>
                            &nbsp;<asp:LinkButton ID="LinkButton4" runat="server" CommandName="Cancel" 
                                CausesValidation="False">Cancel</asp:LinkButton>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                                CommandName="New" Text="New"></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Fields>
            </asp:DetailsView>
        </EmptyDataTemplate>
    </asp:GridView>
    </div><!--End .#featured-post-->
    <asp:SqlDataSource ID="_sdsPublishers" runat="server" 
        ConflictDetection="CompareAllValues" 
        ConnectionString="<%$ ConnectionStrings:DB_BookStoreConnectionString %>" 
        DeleteCommand="DELETE FROM [Publishers] WHERE [PublisherID] = @original_PublisherID AND [PublisherName] = @original_PublisherName AND (([Logo] = @original_Logo) OR ([Logo] IS NULL AND @original_Logo IS NULL)) AND (([Address] = @original_Address) OR ([Address] IS NULL AND @original_Address IS NULL)) AND (([Phone] = @original_Phone) OR ([Phone] IS NULL AND @original_Phone IS NULL)) AND (([Description] = @original_Description) OR ([Description] IS NULL AND @original_Description IS NULL))" 
        InsertCommand="INSERT INTO [Publishers] ([PublisherName], [Logo], [Address], [Phone], [Description]) VALUES (@PublisherName, @Logo, @Address, @Phone, @Description)" 
        OldValuesParameterFormatString="original_{0}" 
        SelectCommand="SELECT * FROM [Publishers]" 
        UpdateCommand="UPDATE [Publishers] SET [PublisherName] = @PublisherName, [Logo] = @Logo, [Address] = @Address, [Phone] = @Phone, [Description] = @Description WHERE [PublisherID] = @original_PublisherID AND [PublisherName] = @original_PublisherName AND (([Logo] = @original_Logo) OR ([Logo] IS NULL AND @original_Logo IS NULL)) AND (([Address] = @original_Address) OR ([Address] IS NULL AND @original_Address IS NULL)) AND (([Phone] = @original_Phone) OR ([Phone] IS NULL AND @original_Phone IS NULL)) AND (([Description] = @original_Description) OR ([Description] IS NULL AND @original_Description IS NULL))">
        <DeleteParameters>
            <asp:Parameter Name="original_PublisherID" Type="Int32" />
            <asp:Parameter Name="original_PublisherName" Type="String" />
            <asp:Parameter Name="original_Logo" Type="String" />
            <asp:Parameter Name="original_Address" Type="String" />
            <asp:Parameter Name="original_Phone" Type="String" />
            <asp:Parameter Name="original_Description" Type="String" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="PublisherName" Type="String" />
            <asp:Parameter Name="Logo" Type="String" />
            <asp:Parameter Name="Address" Type="String" />
            <asp:Parameter Name="Phone" Type="String" />
            <asp:Parameter Name="Description" Type="String" />
            <asp:Parameter Name="original_PublisherID" Type="Int32" />
            <asp:Parameter Name="original_PublisherName" Type="String" />
            <asp:Parameter Name="original_Logo" Type="String" />
            <asp:Parameter Name="original_Address" Type="String" />
            <asp:Parameter Name="original_Phone" Type="String" />
            <asp:Parameter Name="original_Description" Type="String" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="PublisherName" Type="String" />
            <asp:Parameter Name="Logo" Type="String" />
            <asp:Parameter Name="Address" Type="String" />
            <asp:Parameter Name="Phone" Type="String" />
            <asp:Parameter Name="Description" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>
</asp:Content>

